<%--
  Created by IntelliJ IDEA.
  User: TLY
  Date: 2022/12/8
  Time: 11:16
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="./common/taglibs.jsp" %>
${jquery_js}
${validate_jquery_js}
${form_jquery_js}

<html>
<head>
    <title>理发店业务管理系统</title>
    <link type="text/css" rel="stylesheet" href="${ctx}/css/style.css"/>
    <script type="text/javascript" src="${ctx}/scripts/index.js"></script>
    <style>
        label{
            color:red
        }
    </style>
</head>
<body>
<div id="header" class="wrap">

    <div class="navbar">
        <ul class="clearfix">
            <li><a href="${ctx}/index.jsp">首页</a></li>
            <li ><a href="${ctx}/user/getpageusers">会员管理</a></li>
            <li class="current"class="current"><a href="${ctx}/staff/getstaffs">职工管理</a></li>
            <li><a href="${ctx}/order/getorders">订单管理</a></li>
        </ul>
    </div>
</div>
<div id="childNav">
    <div class="welcome wrap">
        管理员${admin.name}您好，欢迎回到管理后台。
    </div>
</div>

<div id="main" class="wrap">
    <div id="menu-mng" class="lefter">
        <div class="box">
            <dl>
         <%--       <dt><a href="${ctx}/user/getpageusers">会员管理</a></dt>
                <dd><em></em><a href="${ctx}/user/adduser">新增会员</a></dd>--%>
             <dt>职工管理</dt>
             <dd><em></em><a href="${ctx}/addstaff.jsp">新增职工</a></dd>
       <%--         <dt>订单管理</dt>
                <dd><em></em><a href="${ctx}/pageproductclass">新增职工</a></dd>--%>
            </dl>
        </div>
    </div>
    <div class="main">
        <h2>添加职工</h2>
        <div class="manage">
            <form action="#" id="myform">
                <table class="form">

                    <tr>
                        <td class="field">姓名(*)：</td>
                        <td><input type="text" class="text" name="staffname" id="staffname" value="" required maxlength="10"/></td>
                    </tr>


                    <tr>
                        <td class="field">手机(*)：</td>
                        <td><input type="text" class="text" name="phone" id="phone" value=""/></td>
                    </tr>

                    <tr>
                        <td class="field">工作(*)：</td>
                        <td>
                            <c:forEach items="${skills}" var="i">
                                <p> <input type="checkbox" name="skill.skillid" value="${i.skillid}" checked />${i.skillname}</p>

                            </c:forEach>

                        </td>


                    </tr>

                    <tr>
                        <td class="field">月薪(*)：</td>
                        <td><input type="text" class="text" name="salary" id="salary" value="" maxlength="10"/></td>
                    </tr>




                    <tr>
                        <td></td>
                        <td><label class="ui-blue"><input type="button" name="button" id="btn" value="添加"/></label></td>
                    </tr>

                </table>
            </form>
        </div>
    </div>
    <div class="clear">

    </div>

</div>

<div id="footer">
    安徽大学江淮学院 2019级 计算机科学与技术专业 陶龙宇 学号JB194033
</div>
<script type="text/javascript">
    $(function () {

        $("#btn").click(function () {

            if($("#myform").valid()){
            var ids = [];
            $('input[name="skill.skillid"]:checked').each(function () {
                ids.push($(this).val()); //向数组中添加元素
            });



            var staffname = $("#staffname").val()


            var phone = $("#phone").val()


            var salary = $("#salary").val()


            $.ajax({
                url: "${ctx}/staff/doaddstaff",
                type: "post",
                traditional: true,
                data: {"staffname": staffname, "ids": ids, "phone": phone, "salary": salary},
                dataType: "json",
                success: function (result) {
                    alert(result.msg)
                    if (result.code == 10000) {
                        location.href = "${ctx}/staff/getstaffs";
                    }
                },
                error: function () {
                    alert("请联系管理员")
                },


            })


      /*      var params = $("#myform").serialize();//获取表单参数值
            $.ajax({
                url: "${ctx}/staff/doaddstaff",
                type: "post",
                data: params,
                dataType: "json",
                success: function (result) {
                    alert(result.msg)
                    if (result.code == 10000) {
                        location.href = "${ctx}/staff/getstaffs";
                    }
                },
                error: function () {
                    alert("请联系管理员")
                },
            })

*/
        }
        })

        $("#myform").validate({
            rules:{
                "staffname":{
                    required:true
                },
                "phone":{
                    required:true,
                    phonelimit:true

                },
                "skill.skillid":{
                    required:true
                },
                "salary":{
                    required:true,
                    min:0,
                    number:true,
                    digits:true

                }
            },
            messages:{
                "staffname":{
                    required:"*请输入职工姓名"
                },
                "phone":{
                    required:"*请输入手机号"
                },
                "skill.skillid":{
                    required:"*工作技能不能为空*"
                },
                "salary":{
                    required:"*薪水不能为空",
                    min:"*最小为0",
                    number:"*请输入正确的数字",
                    digits:"*请输入整数"


                }

            }

        })

        $.validator.addMethod("phonelimit",function(value,element){
            var rule = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/
            return this.optional(element)||(rule.test(value))
        },"*请输入正确的手机号")

    })


</script>

</body>
</html>
